﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;

namespace FX.CC.Andon.UpgradeTool
{
    class Program
    {
        static void Main(string[] args)
        {
            string exePath = string.Empty;
            if (args.Length > 0)
            {
                exePath = args[0];
            }

            Console.WriteLine("Ready to upgrade process....");
            Thread.Sleep(1000);
            Console.WriteLine("Upgrade process started....");
            string exeFolder = Path.GetDirectoryName(exePath);
            string upgradeFolder = exeFolder + "\\Upgrade\\";

            string[] files = Directory.GetFiles(upgradeFolder);
            try
            {
                foreach (var file in files)
                {
                    string shortName = file.Split('\\').Last();
                    File.Copy(file, Path.Combine(exeFolder, shortName), true);
                    File.Delete(file);
                    Console.WriteLine("File : " + shortName + " replaced....");
                }
            }
            catch (IOException ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.WriteLine("Upgrade process succeed....");

            Thread.Sleep(3000);

            if (exePath != string.Empty)
            {
                System.Diagnostics.Process.Start(exePath, string.Empty);
            }
        }
    }
}
